load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")

package(default_visibility = ["//visibility:public"])

rust_binary(
    name = "print",
    srcs = ["main.rs"],
    deps = [
        ":printer",
    ],
)

rust_library(
    name = "printer",
    srcs = [
        "lib.rs",
        "print_generic.rs",
    ] + select({
        "@rules_rust//rust/platform:linux": [
            ":print_linux.rs",
        ],
        "@rules_rust//rust/platform:macos": [
            ":print_macos.rs",
        ],
        "@rules_rust//rust/platform:windows": [
            ":print_windows.rs",
        ],
    }),
    # Because each os specific file is conditionally added to the target,
    # rustfmt does not have all sources to complete formatting. To avoid
    # this failure, rustfmt is not run on this target
    tags = ["norustfmt"],
)

rust_test(
    name = "printer_test",
    crate = ":printer",
    # The same rational used for `printer` applies here. Do not run rustfmt
    # since not all sources are available.
    tags = ["norustfmt"],
)
